<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html>
<head>
<meta charset="UTF-8"/>
<title>运营平台</title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="renderer" content="webkit">
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge">-->
<link type="text/css" rel="stylesheet" href="<?php echo get_style_cdnurl();?>paimai/yunying/css/common.css?v=20170207" />
<link type="text/css" rel="stylesheet" href="<?php echo get_style_cdnurl();?>paimai/yunying/css/table.css?v=20170117" />
<link type="text/css" rel="stylesheet" href="<?php echo get_style_cdnurl();?>paimai/yunying/css/jquery-ui.css" />
<script src="<?php echo get_style_cdnurl();?>paimai/yunying/js/jquery-1.11.1.js" type="text/javascript"></script>
<script src="<?php echo get_style_cdnurl();?>paimai/yunying/js/jquery-ui.min.js" type="text/javascript"></script>
 <script src="<?php echo get_style_cdnurl();?>paimai/yunying/js/yunIndex.js" type="text/javascript"></script>
<script src="<?php echo get_style_cdnurl();?>paimai/yunying/js/jquery-ym-datePlugin-0.1.js" type="text/javascript"></script>
<script src="<?php echo get_style_cdnurl();?>paimai/yunying/js/global.js" type="text/javascript"></script>
<script src="<?php echo get_style_cdnurl();?>paimai/cheshan/js/common.js" type="text/javascript"></script>
<script type="text/javascript" src="<?php echo get_style_cdnurl();?>paimai/yunying/js/jquery.placeholder.min.js"></script>
<script type="text/javascript">
 $(function(){
     $("input").placeholder();
     if (navigator.userAgent.indexOf("Safari") > -1) {
       $("input").css("lineHeight","normal !important");
     };
});
</script>

</head>
<body>
<body>
<div class="header">
<div class="headerCo">
<span>你好,<?php echo ($user_info["real_name"]); ?><a href="<?php echo (WEB_URL); ?>Emp/logout">退出</a></span>
<h1><img src="<?php echo get_style_cdnurl();?>paimai/yunying/images/yun_logo.jpg"></h1>
</div>
</div>

<div class="mian">
    <div class="mianL">
    <dl>
        <dd>
            <a id="menu_sy" href="/Index/index" class="shouye">首页</a>
        </dd>
        <?php foreach ($tree_menu as $key => $value): ?>
          <dd>
            <span id="menu_<?php echo ($value['first_char']); ?>" ><img src="<?php echo get_style_cdnurl();?>paimai/yunying/images/yun_jia.jpg"><?php echo ($value['name']); ?></span>
            <ul style="display: none;">
                <?php if (!empty($value['children'])): ?>
                    <?php foreach ($value['children'] as $k => $v): ?>
                        <li><a id='menu_<?php echo ($v["first_char"]); ?>' href="<?php echo ($v['url']); ?>"><?php echo ($v['name']); ?></a></li>
                    <?php endforeach ?>
                <?php endif ?>
            </ul>
        <?php endforeach ?>
    </dl>
</div>

<?php $menu = 'zhgl.ygzh'; ?>
<?php $menu=json_encode(explode('.', $menu)); ?>
<script>
    $(function () {
        var cur_menu = '<?php echo ($menu); ?>', cur_menu = eval('[' + cur_menu + ']'), cur_menu = cur_menu[0];
        if (cur_menu == "sy") {
            $("#menu_sy").removeClass('shouye').addClass('current');
        }
        $('#menu_' + cur_menu[0]).click();
        $('#menu_' + cur_menu[0]).find("img").attr("src", "http://img1.isou365.cn/paimai/yunying/images/yun_jie.jpg");
        $(".mianL").css("height", $(document).height() - 95);
        $('#menu_' + cur_menu[1]).addClass('current');
    });
</script>

    <div class="mianR">
        <h3 class='cha'>权限设置</h3>
        <div class="broker">
            <h4>员工基本信息</h4>
            <ul class="broker-area clearfix">
                <input type="hidden" name="emp_id" value="<?php echo ($_GET['emp_id']); ?>" />
                <li><span>姓名：</span><span class="broker-text"><?php echo ($user_info["real_name"]); ?></span></li>
                <li><span>手机：</span><span class="broker-text"><?php echo ($user_info["mobile"]); ?></span></li>
                <li><span>用户名：</span><span class="broker-text"><?php echo ($user_info["username"]); ?></span></li>
                <li><span>邮箱：</span><span class="broker-text"><?php echo ($user_info["email"]); ?></span></li>
            </ul>
        </div>
        <div class="associated-store clearfix">
            <h4>权限设置</h4>
            <div class="associated-left">
                <h5>权限组</h5>
                <div class="store-search"><input type="text" value="" id="text" placeholder="请输入关键字" /><input type="button" id="search" value="搜索" /></div>
                <ul class="associated-first">
                    <?php if(is_array($last_group_list)): foreach($last_group_list as $key=>$group): ?><li data-id="<?php echo ($group["id"]); ?>"><i class="add-btn">添加</i><span class="renew"><?php echo ($group["title"]); ?></span><?php endforeach; endif; ?>
                </ul>
                <ul class="associated-last"></ul>
                <div class="associated-not">您搜索的结果不存在！</div>
                <input type="hidden" value="" id="add-text">
            </div>
            <div class="associated-right">
                <h5>已添加的权限组</h5>
                <ul id="jurisdiction">
                    <?php if(is_array($mygroup)): foreach($mygroup as $key=>$my_group): ?><li data-id="<?php echo ($my_group["id"]); ?>"><i class="delete-btn">删除</i><span class="renew"><?php echo ($my_group["title"]); ?></span></li><?php endforeach; endif; ?>
                </ul>
            </div>
        </div>
        <div class="yongBtn">
            <input type="button" value="确认" id="queding" name="queding" class="queding">
            <input type="button" id="cancel" class="quxiao" value="取消">
        </div>
    </div>
</div>
<div class="yunBei"></div>
<script type="text/javascript">
    var role=[];
    var role1=[];
    $(function(){
        $(".associated-last").hide();
        var oLH=$(".associated-first li").outerHeight(true);

        if(($(".associated-first li").length)*oLH>320){
            $(".associated-first").css("overflow-y","scroll");
        }else{
            $(".associated-first").css("overflow-y","auto");
        }
        var oLH1=$(".associated-last li").outerHeight(true);
        if(($(".associated-last li").length)*oLH1>320){
            $(".associated-last").css("overflow-y","scroll");
        }else{
            $(".associated-last").css("overflow-y","auto");
        }
        var oLH2=$(".associated-right ul li").outerHeight(true);
        if(($(".associated-right ul li").length)*oLH2>350){
            $(".associated-right ul").css("overflow-y","scroll");
        }else{
            $(".associated-right ul").css("overflow-y","auto");
        }
        //点击搜索获取输入框的内容与下面的li里的内容匹配，匹配好的li插入
        //associated-last.ul里面并且显示，associated-first.ul隐藏
        $("#search").on("click",function(){
            $(".associated-first").hide();
            $(".associated-last").hide();
            $(".associated-first").prepend($(".associated-last").html());

            $(".associated-last").html("");
            if($("#text").val()==""){
                $(".associated-first").show()
                $(".associated-last").hide();
                $(".associated-not").hide();
            }else{
                $("#text").css("border","solid 1px #ccc");
                var oText=$("#text").val();
                var oSpan=$(".associated-left ul li span");
                $(".associated-last").html("");
                $(".associated-last").hide();
                $(".associated-not").hide();
                for(var i=0;i<oSpan.length;i++){
                    if($(oSpan[i]).html().indexOf(oText)!=-1){
                        var oLi=$(oSpan[i]).parent("li");
                        $(".associated-first").hide()
                        $(".associated-last").show();
                        $(".associated-last").append(oLi);

                    }


                }
                if($(".associated-last").html()==""){
                    $(".associated-not").show();
                }else{
                    $(".associated-not").hide();
                }
            }

        })

        $(".associated-first").on("click","li i.add-btn",function(){
            var oS=$(this).parent("li").find("span").html();
            var iD=$(this).parent("li").attr("data-id");
            $(this).parent("li").remove();
            $(".associated-right ul").prepend("<li data-id="+iD+"><span class='renew'>"+oS+"</span><i class='delete-btn'>删除</i></li>");
            role.push(iD);
           // $("#add-text").val(role);
            if(($(".associated-first li").length)*oLH>320){
                $(".associated-first").css("overflow-y","scroll");
            }else{
                $(".associated-first").css("overflow-y","auto");
            }
        })
        $(".associated-last").on("click","li i.add-btn",function(){
            var oS=$(this).parent("li").find("span").html();
            var iD=$(this).parent("li").attr("data-id");
            $(this).parent("li").remove();
            $(".associated-right ul").prepend("<li data-id="+iD+"><span class='renew'>"+oS+"</span><i class='delete-btn'>删除</i></li>");
            role.push(iD);
            //$("#add-text").val(role);
            if(($(".associated-last li").length)*oLH>320){
                $(".associated-last").css("overflow-y","scroll");
            }else{
                $(".associated-last").css("overflow-y","auto");
            }
        })


        $(".associated-right ul").on("click","li i.delete-btn",function(){
            var oS1=$(this).parent("li").find("span").html();
            var iD1=$(this).parent("li").attr("data-id");
            $(this).parent("li").remove();
            if($(".associated-first").css("display")=="none"){
                $(".associated-last").prepend("<li data-id="+iD1+"><span class='renew'>"+oS1+"</span><i class='add-btn'>添加</i>"+"</li")
            }
            if($(".associated-last").css("display")=="none"){
                $(".associated-first").prepend("<li data-id="+iD1+"><span class='renew'>"+oS1+"</span><i class='add-btn'>添加</i>"+"</li")
            }
            role1.push(iD1);
           // console.log(role1);
            $("#del-text").val(role1);
        })

        $("#queding").on("click",function () {
            submit_alert()
        })

        $("body").on("click",".determine",function () {
             submit_alert();
            //$(".yunBei").css("display","none");
           // $(".chenggong1").remover();
        })
        $("body").on("click",".cancel",function () {
            window.location.href='/Emp/index';
        })
        $("#cancel").on("click",function(){
            if(role.length!=0||role1.length!=0){
                $(".yunBei").css("display","block");
                confirm_alert("您已对数据进行了修改,是否需要保存!");
            }else{
                window.location.href='/Emp/index';
            }
        })

    })


    function submit_alert() {
        a = role;
        b = role1;
        var addArr = array_difference(a, b);
        var delArr = array_difference(b, a);
        //console.log(addArr)
        //$("input['name=emp_id']").val();
        var emp_id = $("input[name ='emp_id']").val();
        var param = {
            'emp_id':emp_id,
            'add_arr':addArr,
            'del_arr':delArr,
        };

        $.post('/Emp/ci_set_group',param,function(data){
            console.log(data);
            if(data.code != 200){
                shibai_alert(data.msg,1500);

            }else {
                $(".chenggong1").remove()
                btn_alert("操作成功",1500,function () {

                    window.location.href='/Emp/index';
                });
            }
        },'json');
    }


    function array_remove_repeat(a) { // 去重
        var r = [];
        for(var i = 0; i < a.length; i ++) {
            var flag = true;
            var temp = a[i];
            for(var j = 0; j < r.length; j ++) {
                if(temp === r[j]) {
                    flag = false;
                    break;
                }
            }
            if(flag) {
                r.push(temp);
            }
        }
        return r;
    }

    function array_difference(a, b) { // 差集 a - b
        var clone = a.slice(0);
        for(var i = 0; i < b.length; i ++) {
            var temp = b[i];
            for(var j = 0; j < clone.length; j ++) {
                if(temp === clone[j]) {
                    clone.splice(j,1);
                }
            }
        }
        return array_remove_repeat(clone);
    }
</script>
<div class="yunBei"></div>
<div class="loading"></div>
</body>
</html>